<?php

class SimpleController extends Controller {
	public function __construct($app='', $controller='', $standalone=true){
		BaseController::__construct($app, $controller, $standalone);
		self::handleCookie(_('cookie'));
		$this->SL = SecureLogin::getInstance();
		$this->checkLogin();
	}
	
	public function launch($action, $params=array()){
		$this->params = $params;
		if(!$this->uid && self::$login){
			$this->uid = self::$login['uid'];
		}
		$this->$action();
		ob_start(array($this, 'applyPostFilter'));
		$this->render($this->view);
		ob_end_flush();
	}
	
	public function checkLogin(){
		if(self::$login === null){
			$login = $this->SL->is_login();
			if(is_array($login) and $login['uid']){
				self::$login = $login;
				$this->removeGuestCookie();
			}else{
				self::$login = false;
				$this->setGuestCookie();
			}
		}
		return self::$login;
	}
}